﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace MODULE_QUANTRIHETHONG
{
    public partial class frm_login : Form
    {
        hethongDataContext context = cls_quantrihethong.getcontext();
        private string susername;
        //private string stenchuhang;
        public bool flag = false;
        public bool exit = false;
        public string _susername
        {
            get { return this.txtusername.Text; }
            set { this.txtusername.Text = value; }
        }
        private string spassword;
        public string _spassword
        {
            get { return this.txtpassword.Text; }
            set { this.txtpassword.Text = value; }
        }
        public frm_login()
        {
            InitializeComponent();
        }

        private void frm_login_Load(object sender, EventArgs e)
        {
        
        }

        private void btdangnhap_Click(object sender, EventArgs e)
        {
            //this._susername = txtusername.Text;
            try
            {
                Cursor.Current = Cursors.AppStarting;
                if (txtusername.Text != "" && txtpassword.Text != "")
                {
                    string username = txtusername.Text;
                    string password = mycryptography.cls_mycryptography.EncryptString("daiviet", this.txtpassword.Text);

                    IEnumerable<DM_nhanvien> nhanviens = from c in context.DM_nhanviens where c.username.Equals(username) where c.password.Equals(password) select c;
                    if (nhanviens.Count() > 0)
                    {
                        
                        frm_main frm = new frm_main();
                        frm._tendangnhap = txtusername.Text;
                        this.MdiParent.Close();
                        frm.Show();
                        flag = true;
                        
                        this.Close();
                        Cursor.Current = Cursors.Default;

                    }
                    else
                    {
                        Cursor.Current = Cursors.Default;
                        MessageBox.Show("Tên đăng nhập hoặc mật khẩu không hợp lệ ");
                        this.txtusername.Text = "";
                        this.txtpassword.Text = "";

                    }
                    
                }
                else
                {
                    MessageBox.Show("Tên đăng nhập và mật khẩu không được rỗng. ");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            
        }

        private void btExit_Click(object sender, EventArgs e)
        {
            Application.Exit();
            exit = true;
           this.Close();
        }
    }
}
